/**
 * Sumpu Inc.
 * Copyright (c) 2011-2012 All Rights Reserved. 
 */
package cn.sumpu.app.guoguojie.domain;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @author nick
 * @version $Id: DoingProductTime.java, v 0.1 2012-9-1 下午03:10:08 nick Exp $
 */
public class DoingProductTime implements java.io.Serializable {

    private static final long serialVersionUID = 6450750988881860721L;
    private String            identifier;
    private String            doingProductId;
    private Double            guoguojieCommissionRate;
    private Double            commissionRate;
    private Boolean           enabled;
    private Date              beginTime;
    private Date              endTime;
    private Date              gmtCreated;
    private Date              gmtModified;

    private CmsContent        cmsContent;
    private DoingProduct      doingProduct;

    public String getIdentifier() {
        return identifier;
    }

    public void setIdentifier(String identifier) {
        this.identifier = identifier;
    }

    public String getDoingProductId() {
        return doingProductId;
    }

    public void setDoingProductId(String doingProductId) {
        this.doingProductId = doingProductId;
    }

    public Double getGuoguojieCommissionRate() {
        return guoguojieCommissionRate;
    }

    public void setGuoguojieCommissionRate(Double guoguojieCommissionRate) {
        this.guoguojieCommissionRate = guoguojieCommissionRate;
    }

    public Boolean getEnabled() {
        return enabled;
    }

    public void setEnabled(Boolean enabled) {
        this.enabled = enabled;
    }

    public Date getBeginTime() {
        return beginTime;
    }

    public void setBeginTime(Date beginTime) {
        this.beginTime = beginTime;
    }

    public Date getEndTime() {
        return endTime;
    }

    public void setEndTime(Date endTime) {
        this.endTime = endTime;
    }

    public Date getGmtCreated() {
        return gmtCreated;
    }

    public void setGmtCreated(Date gmtCreated) {
        this.gmtCreated = gmtCreated;
    }

    public Date getGmtModified() {
        return gmtModified;
    }

    public void setGmtModified(Date gmtModified) {
        this.gmtModified = gmtModified;
    }

    public CmsContent getCmsContent() {
        return cmsContent;
    }

    public void setCmsContent(CmsContent cmsContent) {
        this.cmsContent = cmsContent;
    }

    public DoingProduct getDoingProduct() {
        return doingProduct;
    }

    public void setDoingProduct(DoingProduct doingProduct) {
        this.doingProduct = doingProduct;
    }

    public int getDefaultTime() {
        Date now = new Date();
        if (beginTime != null && endTime != null && now.getTime() < endTime.getTime()) {
            return (int) (endTime.getTime() - now.getTime()) / 1000;
        }
        return 0;
    }
    public String getTime(){
        long day1 = 1000*60*60*24;
        long hou1 = 1000*60*60;
        long min1 = 1000*60;
        long time = endTime.getTime() - new Date().getTime();
        long day = time/day1;
        long hou = (time%day1)/hou1;
        long min = (time%hou1)/min1;
        return day + "天" + hou + "小时" + min + "分";
    }

    public Map<String, Object> getTimeView() {
        if (beginTime == null || endTime == null) {
            return null;
        }
        Map<String, Object> map = new HashMap<String, Object>();
        Date now = new Date();
        if (now.getTime() < beginTime.getTime()) {//未开始
            map.put("status", 1);
            map.put("defaultTime", (int) (beginTime.getTime() - now.getTime()) / 1000);
        } else if (now.getTime() >= beginTime.getTime() && now.getTime() <= endTime.getTime()) {
            map.put("status", 2);
            map.put("defaultTime", (int) (endTime.getTime() - now.getTime()) / 1000);//现在大于等于开始时间小于等于结束时间则开始状态
        } else if (now.getTime() > endTime.getTime()) {
            map.put("status", 3);
            map.put("defaultTime", (int) (now.getTime() - endTime.getTime()) / 1000);//结束状态
        }
        return map;
    }

    public void setCommissionRate(Double commissionRate) {
        this.commissionRate = commissionRate;
    }

    public Double getCommissionRate() {
        return commissionRate;
    }

}
